/*
 * Copyright (C) 2011 Project R'yleh Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.Arkham;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

public class NewGame02 extends Activity  implements OnClickListener{

	TextView speaking, text1;
	String selection, yes, no;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		//removes title bar and sets the theme
        this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
        
		super.onCreate(savedInstanceState);
		setContentView(R.layout.newgame02);
		
		speaking = (TextView) findViewById(R.id.ng2_speaking);
		text1 = (TextView) findViewById(R.id.ng2_text);
		
		speaking.setText( "Head Master: ");
		text1.setText(Dialogue.newGame03());
		
		Spinner spinner = (Spinner) findViewById(R.id.newgame_spinner1);
	    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
	            this, R.array.yes_no_array, android.R.layout.simple_spinner_item);
	    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	    spinner.setAdapter(adapter);
	    yes = adapter.getItem(0).toString();
	    no = adapter.getItem(1).toString();
	    
	    View newGameInfoButton2 = findViewById(com.Arkham.R.id.newGame_button2);
		newGameInfoButton2.setOnClickListener(this);
		
	    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
	}

	public void onClick(View v) {
		Intent i;
	    if(selection == no){
	    	  i = new Intent(this, NewGame01.class);
		      startActivity(i);
	    }
	    else if(selection == yes){
			  //equip new starting character with starting equipment
			  GameFile.party.inventory.gainItem(Armory.DullPencil());
			  GameFile.party.inventory.gainItem(Armory.UsedEraser());
			  GameFile.party.inventory.gainItem(Armory.DunceCap());
			  GameFile.party.inventory.gainItem(Armory.StreetCloths());
			  GameFile.party.inventory.gainItem(Armory.Sneakers());
			  GameFile.party.equip(0, Constants.R_HAND, GameFile.party.characters[0]);
		  	  GameFile.party.equip(1, Constants.L_HAND, GameFile.party.characters[0]);
			  GameFile.party.equip(2, Constants.HEAD, GameFile.party.characters[0]);
			  GameFile.party.equip(3, Constants.BODY, GameFile.party.characters[0]);
			  GameFile.party.equip(4, Constants.FEET, GameFile.party.characters[0]);
	    	  i = new Intent(this, Introductions.class);
		      startActivity(i);
		      //check to see if this jumps to main
		      finish();
	    }
	    else{}
	}
	
	public class MyOnItemSelectedListener implements OnItemSelectedListener {

	    public void onItemSelected(AdapterView<?> parent,
	        View view, int pos, long id) {
	      selection = parent.getItemAtPosition(pos).toString();
	    }

	    public void onNothingSelected(AdapterView parent) {
	      // Do nothing.
	    }
	}
}